<?php /* УТФ-8:fix */

class SPIcontroller__widget__spaw2 extends SPIcontroller__widget
{
    public function __construct()
    {
        require_once( SPIcfg::$util['spaw2']['base_script'] );
    }

    public function open()
    {
        return new SPIcontroller__widget__spaw2__thread;
    }
}

class SPIcontroller__widget__spaw2__thread
{
    public function __construct()
    {
        $this->pages = array();
        return true;
    }

    public function addpage( $varname, $value, $tabname = '' )
    {
        if( $this->pages === null )
        {
            return false;
        }
        
        $this->pages[] = array(
            'varname' => $varname,
            'value'   => $value,
            'tabname' => $tabname,
        );

        return true;
    }

    public function render()
    {
        if( $this->pages === null )
        {
            return false;
        }
        
        if( count( $this->pages ) == 0 )
        {
            return false;
        }

        $spaw_object = null;

        foreach( $this->pages as $dataitem )
        {
            if( $spaw_object === null )
            {
                $spaw_object = new SpawEditor( $dataitem['varname'] );
            }

            $spaw_object->addPage( new SpawEditorPage( $dataitem['varname'], $dataitem['tabname'], $dataitem['value'] ) );
        }

        $this->pages = null;

        return $spaw_object->getHtml();
    }
}
